package com.guigu.alibaba.service;


import com.guigu.alibaba.dao.OrderDao;
import com.guigu.alibaba.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class OrderServiceImpl implements OrderService {


    @Resource
    private StorageService storageService;
    @Resource
    private AccountService accountService;

    @Resource
    private OrderDao orderDao;

    public void create(Order order) {
        log.info("---------开始创建订单");
        orderDao.create(order);
        log.info("---------开始减库存");
        storageService.decrease(order.getProductId(), order.getCount());
        log.info("---------开始增加用户账单");
        accountService.decrease(order.getUserId(), order.getMoney());
        log.info("---------开始更新订单支付状态");
        orderDao.updateStatus(order.getId(), order.getStatus());
    }
}
